import qs from 'qs';
import request from "../index";
import { version } from "@/config";
import { formatDate } from "@/utils";

// 1.产品相关政策信息
export function productInstruction({ goodsId, goodsExtendName }) {
  return request({
    url: `/ssop/api/goods-v${version}/applet/goods/predefined/instructions`,
    method: "get",
    params: {
      goodsId,
      goodsExtendName,
    },
  })
}
// 2.入园时间段
export function productExtend({
  goodsId,
  goodsExtendName,
  useDate = formatDate(new Date()),
}) {
  return request({
    url: `/ssop/api/goods-v${version}/applet/goods/extend`,
    method: "get",
    params: {
      goodsId,
      goodsExtendName,
      useDate,
    },
  });
}

// 3. 产品价格信息
export function productPrice(params) {
  const { startDate, endDate } = params;
  let url = `/ssop/api/goods-v${version}/applet/goods/extend/price?${qs.stringify(params)}`;
  // 酒店
  if (startDate !== endDate) {
    url = `/ssop/api/goods-v${version}/applet/goods/extend/price/hotel?${qs.stringify(params)}`;
  }
 
  return request({
    url,
    method: "post",
  })
}
// 价格日历 
export function priceCalendar({
  goodsExtendId,
  distributorMobile = ""
}) {
  return request({
    url: `/ssop/api/goods-v${version}/goods-extend/list/price/calendar`,
    method: "get",
    params: {
      goodsExtendId,
      distributorMobile
    }
  });
}

// 游客列表
export function customerList() {
  return request({
    url: `/ssop/api/member-v${version}/member/contact/list`,
    method: "get",
  });
}

// 添加游客信息
export function addCustomer(data) {
  return request({
    url: `/ssop/api/member-v${version}/member/contact/add`,
    method: "post",
    data,
  });
}

// 创建订单，提交
export function createOrder(type = "", params) {
  if (type === "/hotel") {
    return request({
      url: `/ssop/api/order-v${version}/order/create/hotel`,
      method: "POST",
      data: params,
    });
  } else if (type === "/ticket") {
    return request({
      url: `/ssop/api/order-v${version}/order/create/ticket`,
      method: "POST",
      data: params,
    });
  } else {
    return request({
      url: `/ssop/api/order-v${version}/order/create/experience`,
      method: "POST",
      data: params,
    });
  }
}

// H5 支付
export function orderPayH5(orderId) {
  return request({
    url: `/ssop/api/order-v${version}/order/pay/h5`,
    method: "POST",
    data: {
      orderId,
      orderClient: 5
    },
  });
}

// 获取支付订单状态
export function orderPayStatus(orderId) {
  return request({
    url: `/ssop/api/order-v${version}/refactor/applet/order/info?orderId=${orderId}`,
    method: "get",
  });
}